<%@page import="java.sql.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>后台|银光云-为银光字幕组提供最优质的云存储服务 - Powered by 金鸡独立</title>
<%!
	class UploadList{
		int id;
		String name;
		String datetime;
		String detail;
		boolean hidden;
		int count;
		String file;
	}
%>
<%
	UploadList[] ul=null;
	String user=null;
	Cookie[] cookie=request.getCookies();
	if(cookie!=null){
		for(int i=0;i<cookie.length;i++){
			if(cookie[i].getName().equals("SilverCouldUserName")==true){
				user=cookie[i].getValue();
			}
		}
	}
	if((user=="")||(user==null)){
		out.println("您还没有登陆，请进入登陆页面登陆：<br/>");
		out.println("<a href=\"index.jsp\">重新登陆</a>");
		return ;
	}
%>
<!-- 查询数据库并调出本帐户上传记录  -->
<%
	Class.forName("com.mysql.jdbc.Driver");
	Connection con=DriverManager.getConnection((String) application.getAttribute("dburl"),(String) application.getAttribute("username"),(String) application.getAttribute("password"));
	Statement s=con.createStatement();
	String sqls1="SELECT id FROM user WHERE name=\'"+user+"\'";
	ResultSet rs=null;
	rs=s.executeQuery(sqls1);
	if((rs==null)||(rs.last()==false)){
		out.println("致命错误-0001：后台无法找到数据库中的userid，如果需要解决，请通知QQ：2276768747");
		return ;
	}
	rs.beforeFirst();
	rs.next();
	String userid=rs.getString(1);
	String sqls2="SELECT id,name,datetime,detail,hidden,count,file FROM data WHERE userid="+userid;
	rs=s.executeQuery(sqls2);
	rs.last();
	int len=rs.getRow();
	rs.beforeFirst();
	if(len>0){
		ul=new UploadList[len];
		for(int i=0;i<len;++i) ul[i]=new UploadList();
		rs.next();
		for(int i=0;i<len;++i){
			ul[i].id=rs.getInt(1);
			ul[i].name=rs.getString(2);
			if(ul[i].name.length()>15) ul[i].name=ul[i].name.substring(0,16)+"……";
			ul[i].datetime=rs.getString(3);
			ul[i].detail=rs.getString(4);
			if(ul[i].detail.length()>15) ul[i].detail=ul[i].detail.substring(0,16)+"……";
			ul[i].hidden=rs.getBoolean(5);
			ul[i].count=rs.getInt(6);
			ul[i].file=rs.getString(7);
			if(ul[i].file.length()>15) ul[i].file=ul[i].file.substring(0,16)+"……";
			rs.next();
		}
	}
	session.setAttribute("username", user);
	session.setAttribute("userid", userid);
%>
</head>
<body>
<!-- 后台主页面 -->
<center>
<h1><font color="red">银光字幕组专属云服务后台管理系统-主页</font></h1>
当前账户：<%=user %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="logout.jsp">安全注销</a><br/>
已上传文件列表：
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="record.jsp">登记新资源</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<!-- 上传文件的内建FTP没有完成，暂不显示
<a href="upload.jsp">上传新文件到data目录</a> -->
<br/>
<%if(ul!=null){%>
<table border="1">
	<tr>
		<th>序号</th>
		<th>标题</th>
		<th>上传时间</th>
		<th>描述</th>
		<th>是否隐藏</th>
		<th>访问次数</th>
		<th>文件名</th>
		<th>相关操作</th>
	</tr>
<%
	for(int i=0;i<len;++i){
		out.println("<tr>");
		out.println("	<td>"+ul[i].id+"</td>");
		out.println("	<td>"+ul[i].name+"</td>");
		out.println("	<td>"+ul[i].datetime+"</td>");
		out.println("	<td>"+ul[i].detail+"</td>");
		out.println("	<td>"+ul[i].hidden+"</td>");
		out.println("	<td>"+ul[i].count+"</td>");
		out.println("	<td>"+ul[i].file+"</td>");
		out.println("	<td>");
		out.println("		<a href=\"edit.jsp?id="+ul[i].id+"\">编辑</a>");
		out.println("		<a href=\"delete.jsp?id="+ul[i].id+"\">删除</a>");
		out.println("		<a href=\"/SilverCould/page/watch.jsp?id="+ul[i].id+"\">访问</a>");
		out.println("	</td>");
		out.println("</tr>");
	}
%>
<%}else{%>
<font color="red">本用户还未上传资源</font>
<%}%>
</table>
</center>
</body>
</html>